package com.letwal.cmcvnd.home

import android.annotation.SuppressLint
import android.view.View
import androidx.lifecycle.ViewModel
import androidx.navigation.findNavController
import com.letwal.cmcvnd.R
import com.letwal.cmcvnd.base.BaseActivity
import com.letwal.cmcvnd.databinding.ActivityHomeBinding
import com.letwal.cmcvnd.earn.EarnFragmentDirections
import com.letwal.cmcvnd.enums.PageTagEnum
import com.letwal.cmcvnd.me.MeHomeFragmentDirections
import java.lang.ref.WeakReference

@SuppressLint("CustomSplashScreen")
class HomeActivity : BaseActivity() {

    var weakHomeFragment: WeakReference<HomeFragment>? = null

    private lateinit var mActivityBinding: ActivityHomeBinding

    override fun onBindingViewModel(): List<ViewModel>? {
        val list = mutableListOf<ViewModel>()
        return list
    }

    override fun onBindingViewTag(): String {
        return PageTagEnum.home.name.uppercase()
    }

    override fun onBindingContentView(): View {
        mActivityBinding = ActivityHomeBinding.inflate(layoutInflater)
        return mActivityBinding.root
    }

    override fun onContentViewBinded() {
        try {
            mActivityBinding.bottomTabBarHome.setOnActionClickListener {
                when (it) {
                    0 -> {
                        if (findNavController(R.id.navHomeFragment).currentDestination?.id == R.id.not_loan_me) {
                            findNavController(R.id.navHomeFragment)
                                .navigate(MeHomeFragmentDirections.toNotLoanHome())

                        } else if (findNavController(R.id.navHomeFragment).currentDestination?.id == R.id.not_loan_statement) {
                            findNavController(R.id.navHomeFragment)
                                .navigate(EarnFragmentDirections.toNotLoanHome())
                        }
                    }
                    1 -> {
                        if (findNavController(R.id.navHomeFragment).currentDestination?.id == R.id.not_loan_home) {
                            findNavController(R.id.navHomeFragment)
                                .navigate(HomeFragmentDirections.toNotLoanStatement())

                        } else if (findNavController(R.id.navHomeFragment).currentDestination?.id == R.id.not_loan_me) {
                            findNavController(R.id.navHomeFragment)
                                .navigate(MeHomeFragmentDirections.toNotLoanStatement())
                        }
                    }
                    2 -> {
                        if (findNavController(R.id.navHomeFragment).currentDestination?.id == R.id.not_loan_home) {
                            findNavController(R.id.navHomeFragment)
                                .navigate(HomeFragmentDirections.toNotLoanMe())

                        } else if (findNavController(R.id.navHomeFragment).currentDestination?.id == R.id.not_loan_statement) {
                            findNavController(R.id.navHomeFragment)
                                .navigate(EarnFragmentDirections.toNotLoanMe())
                        }
                    }
                    else -> {

                    }
                }
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    fun toEarnTab() {
        mActivityBinding.bottomTabBarHome.setTabClick(1)
    }
}